package com.cmc.cloud.cmclink.doc.util;

import com.cmes.framework.common.util.date.DateUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author lzp
 */
@Component
public class LocalDateTimeUtil {

    private static final DateTimeFormatter INPUT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern(DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);

    public LocalDateTime timeConvert(String time) {
        return LocalDateTime.parse(time, INPUT_FORMATTER);
    }

    public LocalDateTime secondConvert(String time) {
        return LocalDateTime.parse(time, FORMATTER);
    }

    public Boolean isValid(String time) {
        try {
            LocalDateTime.parse(time, INPUT_FORMATTER);
            return false;
        } catch (Exception e) {
            return true;
        }

    }
}
